package com.kafka;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName KafkaConsumer
 * @Description kafka消费者
 * @Author zhengmw
 * @Data 2024/7/26 10:40
 */
@Slf4j
@Component
public class KafkaConsumer {
    @KafkaListener(topics = TopicConstant.TOPIC_TEST, groupId = "ck")
    public void listener(String message) {

        JSONObject jsonObject = JSONUtil.parseObj(message);
        UserDTO userDTO = BeanUtil.toBean(jsonObject, UserDTO.class);
        log.info("kafka消费者，消费消息:{}", userDTO);
    }
}
